using Circus.CodeEditor;
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace Circus.Syntax.CodeCompletion
{
	public class CodeSnippetMember : ICodeSnippetMember, IComparable
	{
		private string name = string.Empty;
		private string path = string.Empty;
		private int imageIndex = -1;
		private CodeSnippetMembers parent;
		private CodeSnippetMembers members;
		private CodeSnippets snippets;
		public virtual string Name
		{
			get
			{
				return this.name;
			}
			set
			{
				if (this.name != value)
				{
					this.name = value;
					this.OnNameChanged();
				}
			}
		}
		public virtual string EditPath
		{
			get
			{
				string text = string.Empty;
				for (ICodeSnippetMember codeSnippetMember = this; codeSnippetMember != null; codeSnippetMember = ((codeSnippetMember.Parent != null) ? codeSnippetMember.Parent.Parent : null))
				{
					text = ((text == string.Empty) ? codeSnippetMember.Name : (codeSnippetMember.Name + SyntaxConsts.DefaultSnippetPathSeparator + text));
				}
				if (text != string.Empty)
				{
					text += SyntaxConsts.DefaultSnippetPathSeparator;
				}
				return text;
			}
		}
		public virtual string Path
		{
			get
			{
				return this.path;
			}
			set
			{
				if (this.path != value)
				{
					this.path = value;
					this.OnPathChanged();
				}
			}
		}
		public virtual int ImageIndex
		{
			get
			{
				return this.imageIndex;
			}
			set
			{
				if (this.imageIndex != value)
				{
					this.imageIndex = value;
					this.OnImageIndexChanged();
				}
			}
		}
		public virtual CodeSnippetMembers Members
		{
			get
			{
				return this.members;
			}
		}
		public virtual CodeSnippets Snippets
		{
			get
			{
				return this.snippets;
			}
		}
		public virtual ICodeSnippetsProvider SnippetsAndMembers
		{
			get
			{
				ICodeSnippetsProvider result;
				if (this.members.Count == 0)
				{
					result = this.snippets;
				}
				else
				{
					if (this.snippets.Count == 0)
					{
						result = this.members;
					}
					else
					{
						ICodeSnippetsProvider codeSnippetsProvider = new CodeSnippetsProvider(this);
						using (IEnumerator<IComparable> enumerator = this.snippets.GetEnumerator())
						{
							while (enumerator.MoveNext())
							{
								CodeSnippet item = (CodeSnippet)enumerator.Current;
								codeSnippetsProvider.Add(item);
							}
						}
						using (IEnumerator<IComparable> enumerator = this.members.GetEnumerator())
						{
							while (enumerator.MoveNext())
							{
								ICodeSnippetMember item2 = (ICodeSnippetMember)enumerator.Current;
								codeSnippetsProvider.Add(item2);
							}
						}
						result = codeSnippetsProvider;
					}
				}
				return result;
			}
		}
		public virtual CodeSnippetMembers Parent
		{
			get
			{
				return this.parent;
			}
			set
			{
				if (this.parent != value)
				{
					this.parent = value;
					this.OnParentChanged();
				}
			}
		}
		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
	
		protected virtual void OnNameChanged()
		{
		}
		protected virtual void OnPathChanged()
		{
		}
		protected virtual void OnImageIndexChanged()
		{
		}
		protected virtual void OnParentChanged()
		{
		}
		public CodeSnippetMember()
		{
			this.members = new CodeSnippetMembers(this);
			this.snippets = new CodeSnippets(this);
		}
		public CodeSnippetMember(CodeSnippetMembers parent) : this()
		{
			this.parent = parent;
		}
		public virtual int CompareTo(object value)
		{
			if (value is ICodeSnippetMember)
			{
				return string.Compare(this.name, ((ICodeSnippetMember)value).Name, true);
			}
			throw new ArgumentException();
		}
	}
}
